package com.fengchunge.controller;

import com.fengchunge.common.ServerResponse;
import com.fengchunge.pojo.UserCollection;
import com.fengchunge.pojo.UserCollectionBack;
import com.fengchunge.pojo.UserInfo;
import com.fengchunge.service.IUserOperationService;
import com.fengchunge.vo.CollectionResponseVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description:
 * @author: mingtai
 * @createDate: 23:35 2021/12/5
 * @version: 1.0
 */
@Controller
@RequestMapping("/user/")
public class UserOperationController {

    @Autowired
    private IUserOperationService iUserOperationService;


    /**
     * 收藏
     *
     * @param userCollection 用户信息
     * @return 成功
     */
    @RequestMapping(value = "collection_movie.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<CollectionResponseVo> collectionMovie(UserCollectionBack userCollection) {

        return iUserOperationService.collectionMovie(userCollection);
    }

    /**
     * 取消收藏
     *
     * @param uid     用户id
     * @param movieId 电影id
     * @return 成功失败
     */
    @RequestMapping(value = "cancel_collection_movie.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<Boolean> cancelCollectionMovie(@RequestParam(value = "uid", defaultValue = "1") Long uid,
                                                         @RequestParam(value = "movieId", defaultValue = "1") Long movieId) {

        return iUserOperationService.cancelCollectionMovie(uid, movieId);
    }

    /**
     * 根据uid获取收藏列表
     * @param pageNum 页码
     * @param pageSize 页大小
     * @param uid uid
     * @return list
     */
    @RequestMapping(value = "get_collection_list.do", method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse<PageInfo> getCollectionList(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                                      @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                                      @RequestParam(value = "uid", defaultValue = "10") Long uid) {

        return iUserOperationService.getCollectionList(pageNum, pageSize, uid);
    }


}



